Sfoglia il codice sorgente

cmUdpPort.h/c:Added cmUdpAddrToString().

master
kevin 11 anni fa
parent
commit
6074e052f0
2 ha cambiato i file con 20 aggiunte e 0 eliminazioni
  1. 17
    0
      cmUdpPort.c
  2. 3
    0
      cmUdpPort.h

+ 17
- 0
cmUdpPort.c Vedi File

@@ -42,6 +42,7 @@ typedef struct
42 42
   unsigned        recvCnt;
43 43
   unsigned        queCbCnt;
44 44
   unsigned        errCnt;
45
+  cmChar_t        ntopBuf[ INET_ADDRSTRLEN+1 ]; // use INET6_ADDRSTRLEN for IPv6
45 46
 } cmUdp_t;
46 47
 
47 48
 cmUdpH_t cmUdpNullHandle = cmSTATIC_NULL_HANDLE;
@@ -545,3 +546,19 @@ cmUdpRC_t cmUdpInitAddr( cmUdpH_t h, const char* addrStr, cmUdpPort_t portNumber
545 546
   cmUdp_t* p = _cmUdpHandleToPtr(h);
546 547
   return _cmUdpInitAddr(p,addrStr,portNumber,retAddrPtr);
547 548
 }
549
+
550
+const cmChar_t* cmUdpAddrToString( cmUdpH_t h, const struct sockaddr_in* addr )
551
+{
552
+  cmUdp_t* p = _cmUdpHandleToPtr(h);
553
+
554
+  _cmUdpClear_errno();
555
+  
556
+  if( inet_ntop(AF_INET, addr,  p->ntopBuf, INET_ADDRSTRLEN) == NULL)
557
+  {
558
+    cmErrSysMsg(&p->err,kNtoPFailUdpRC,errno, "Network address to string conversion failed." );
559
+    return NULL;
560
+  }
561
+  
562
+  p->ntopBuf[INET_ADDRSTRLEN]=0;
563
+  return p->ntopBuf;
564
+}

+ 3
- 0
cmUdpPort.h Vedi File

@@ -19,6 +19,7 @@ extern "C" {
19 19
     kSockRecvFailUdpRC,
20 20
     kSockSelectFailUdpRC,
21 21
     kPtoNFailUdpRC,
22
+    kNtoPFailUdpRC,
22 23
     kNotConnectedUdpRC,
23 24
     kThreadFailUdpRC,
24 25
     kQueueFailUdpRC,
@@ -115,6 +116,8 @@ extern "C" {
115 116
   // Prepare a struct sockadddr_in for use with cmUdpSendTo()
116 117
   cmUdpRC_t cmUdpInitAddr( cmUdpH_t h, const char* addrStr, cmUdpPort_t portNumber, struct sockaddr_in* retAddrPtr );
117 118
 
119
+  const cmChar_t*  cmUdpAddrToString( cmUdpH_t h, const struct sockaddr_in* addr );
120
+
118 121
 #ifdef __cplusplus
119 122
 }
120 123
 #endif

Loading…
Annulla
Salva