浏览代码

cmUdpPort.h/c:Added cmInvalidUdpPortNumber and check for definition of HOST_NAME_MAX.

master
kevin 11 年前
父节点
当前提交
0dd7cdbbe9
共有 2 个文件被更改,包括 17 次插入3 次删除
  1. 7
    0
      cmUdpPort.c
  2. 10
    3
      cmUdpPort.h

+ 7
- 0
cmUdpPort.c 查看文件

@@ -18,6 +18,10 @@
18 18
 #define cmUdp_SYS_ERR (-1)
19 19
 #define cmUdp_NULL_SOCK (-1)
20 20
 
21
+#ifndef HOST_NAME_MAX
22
+#define HOST_NAME_MAX  _POSIX_HOST_NAME_MAX
23
+#endif
24
+
21 25
 enum
22 26
 {
23 27
   kIsConnectedUdpFl = 0x01,
@@ -99,6 +103,9 @@ cmUdpRC_t _cmUdpFree( cmUdp_t* p )
99 103
 cmUdpRC_t _cmUdpInitAddr( cmUdp_t* p, const char* addrStr, cmUdpPort_t portNumber, struct sockaddr_in* retAddrPtr )
100 104
 {
101 105
 	memset(retAddrPtr,0,sizeof(struct sockaddr_in));
106
+
107
+  if( portNumber == kInvalidUdpPortNumber )
108
+    return cmErrMsg(&p->err,kInvalidPortNumbUdpRC,"The port number %i cannot be used.",kInvalidUdpPortNumber);
102 109
 	
103 110
 	if( addrStr == NULL )
104 111
 		retAddrPtr->sin_addr.s_addr 	= htonl(INADDR_ANY);

+ 10
- 3
cmUdpPort.h 查看文件

@@ -26,12 +26,13 @@ extern "C" {
26 26
     kRecvBufOverflowUdpRC,
27 27
     kBufTooSmallUdpRC,
28 28
     kHostNameFailUdpRC,
29
+    kInvalidPortNumbUdpRC,
29 30
     kTimeOutUdpRC
30 31
   };
31 32
 
32
-  typedef cmRC_t     cmUdpRC_t;
33
-  typedef cmHandle_t cmUdpH_t;
34
-  typedef u_short    cmUdpPort_t;
33
+  typedef cmRC_t         cmUdpRC_t;
34
+  typedef cmHandle_t     cmUdpH_t;
35
+  typedef unsigned short cmUdpPort_t;
35 36
 
36 37
   extern cmUdpH_t cmUdpNullHandle;
37 38
 
@@ -46,6 +47,12 @@ extern "C" {
46 47
     
47 48
   };
48 49
 
50
+  enum
51
+  {
52
+    // port 0 is reserved by and is therefore a convenient invalid port number
53
+    kInvalidUdpPortNumber = 0 
54
+  };
55
+
49 56
   cmUdpRC_t cmUdpAlloc( cmCtx_t* ctx, cmUdpH_t* hp );
50 57
   cmUdpRC_t cmUdpFree(  cmUdpH_t* hp );
51 58
 

正在加载...
取消
保存