3636
3737#ifdef DBG_SECTION_NAME
3838#undef DBG_SECTION_NAME
39- #define DBG_SECTION_NAME "[ AT_SOC] "
39+ #define DBG_SECTION_NAME "AT_SOC"
4040#endif
4141
42-
4342#define HTONS_PORT (x ) ((((x) & 0x00ffUL) << 8) | (((x) & 0xff00UL) >> 8))
4443#define NIPQUAD (addr ) \
4544 ((unsigned char *)&addr)[0], \
@@ -89,7 +88,7 @@ static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length)
8988 at_recv_pkt_t pkt ;
9089
9190 pkt = (at_recv_pkt_t ) rt_calloc (1 , sizeof (struct at_recv_pkt ));
92- if (! pkt )
91+ if (pkt == RT_NULL )
9392 {
9493 LOG_E ("No memory for receive packet table!" );
9594 return 0 ;
@@ -340,7 +339,7 @@ int at_socket(int domain, int type, int protocol)
340339
341340 /* allocate and initialize a new AT socket */
342341 sock = alloc_socket ();
343- if (! sock )
342+ if (sock == RT_NULL )
344343 {
345344 LOG_E ("Allocate a new AT socket failed!" );
346345 return RT_NULL ;
@@ -381,14 +380,16 @@ int at_closesocket(int socket)
381380 struct at_socket * sock ;
382381 enum at_socket_state last_state ;
383382
384- if (! at_dev_ops )
383+ if (at_dev_ops == RT_NULL )
385384 {
386- LOG_E ("Please register AT device socket options first!" );
387385 return -1 ;
388386 }
389387
390- if ((sock = at_get_socket (socket )) == RT_NULL )
388+ sock = at_get_socket (socket );
389+ if (sock == RT_NULL )
390+ {
391391 return -1 ;
392+ }
392393
393394 last_state = sock -> state ;
394395
@@ -410,14 +411,16 @@ int at_shutdown(int socket, int how)
410411{
411412 struct at_socket * sock ;
412413
413- if (! at_dev_ops )
414+ if (at_dev_ops == RT_NULL )
414415 {
415- LOG_E ("Please register AT device socket options first!" );
416416 return -1 ;
417417 }
418418
419- if ((sock = at_get_socket (socket )) == RT_NULL )
419+ sock = at_get_socket (socket );
420+ if (sock == RT_NULL )
421+ {
420422 return -1 ;
423+ }
421424
422425 if (sock -> state == AT_SOCKET_CONNECT )
423426 {
@@ -434,7 +437,9 @@ int at_bind(int socket, const struct sockaddr *name, socklen_t namelen)
434437{
435438
436439 if (at_get_socket (socket ) == RT_NULL )
440+ {
437441 return -1 ;
442+ }
438443
439444 return 0 ;
440445}
@@ -470,7 +475,8 @@ static void at_recv_notice_cb(int socket, at_socket_evt_t event, const char *buf
470475 RT_ASSERT (bfsz );
471476 RT_ASSERT (event == AT_SOCKET_EVT_RECV );
472477
473- if ((sock = at_get_socket (socket )) == RT_NULL )
478+ sock = at_get_socket (socket );
479+ if (sock == RT_NULL )
474480 return ;
475481
476482 /* put receive buffer to receiver packet list */
@@ -506,14 +512,13 @@ int at_connect(int socket, const struct sockaddr *name, socklen_t namelen)
506512 char ipstr [16 ] = { 0 };
507513 int result = 0 ;
508514
509- if (! at_dev_ops )
515+ if (at_dev_ops == RT_NULL )
510516 {
511- LOG_E ("Please register AT device socket options first!" );
512517 return -1 ;
513518 }
514519
515520 sock = at_get_socket (socket );
516- if (! sock )
521+ if (sock == RT_NULL )
517522 {
518523 result = -1 ;
519524 goto __exit ;
@@ -560,21 +565,19 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f
560565 int result = 0 ;
561566 size_t recv_len = 0 ;
562567
563- if (! mem || len == 0 )
568+ if (mem == RT_NULL || len == 0 )
564569 {
565570 LOG_E ("AT recvfrom input data or length error!" );
566- result = -1 ;
567- goto __exit ;
571+ return -1 ;
568572 }
569573
570- if (! at_dev_ops )
574+ if (at_dev_ops == RT_NULL )
571575 {
572- LOG_E ("Please register AT device socket options first!" );
573576 return -1 ;
574577 }
575578
576579 sock = at_get_socket (socket );
577- if (! sock )
580+ if (sock == RT_NULL )
578581 {
579582 result = -1 ;
580583 goto __exit ;
@@ -686,22 +689,21 @@ int at_sendto(int socket, const void *data, size_t size, int flags, const struct
686689 struct at_socket * sock ;
687690 int len , result = 0 ;
688691
689- if (! at_dev_ops )
692+ if (at_dev_ops == RT_NULL )
690693 {
691- LOG_E ("Please register AT device socket options first!" );
692694 result = -1 ;
693695 goto __exit ;
694696 }
695697
696- if (! data || size == 0 )
698+ if (data == RT_NULL || size == 0 )
697699 {
698700 LOG_E ("AT sendto input data or size error!" );
699701 result = -1 ;
700702 goto __exit ;
701703 }
702704
703705 sock = at_get_socket (socket );
704- if (! sock )
706+ if (sock == RT_NULL )
705707 {
706708 result = -1 ;
707709 goto __exit ;
@@ -780,14 +782,14 @@ int at_getsockopt(int socket, int level, int optname, void *optval, socklen_t *o
780782 struct at_socket * sock ;
781783 int32_t timeout ;
782784
783- if (! optval || ! optlen )
785+ if (optval == RT_NULL || optlen == RT_NULL )
784786 {
785787 LOG_E ("AT getsocketopt input option value or option length error!" );
786788 return -1 ;
787789 }
788790
789791 sock = at_get_socket (socket );
790- if (! sock )
792+ if (sock == RT_NULL )
791793 {
792794 return -1 ;
793795 }
@@ -827,14 +829,14 @@ int at_setsockopt(int socket, int level, int optname, const void *optval, sockle
827829{
828830 struct at_socket * sock ;
829831
830- if (! optval )
832+ if (optval == RT_NULL )
831833 {
832834 LOG_E ("AT setsockopt input option value error!" );
833835 return -1 ;
834836 }
835837
836838 sock = at_get_socket (socket );
837- if (! sock )
839+ if (sock == RT_NULL )
838840 {
839841 return -1 ;
840842 }
@@ -923,15 +925,14 @@ struct hostent *at_gethostbyname(const char *name)
923925 static char s_hostname [DNS_MAX_NAME_LENGTH + 1 ];
924926 size_t idx = 0 ;
925927
926- if (! name )
928+ if (name == RT_NULL )
927929 {
928930 LOG_E ("AT gethostbyname input name error!" );
929931 return RT_NULL ;
930932 }
931933
932- if (! at_dev_ops )
934+ if (at_dev_ops == RT_NULL )
933935 {
934- LOG_E ("Please register AT device socket options first!" );
935936 return RT_NULL ;
936937 }
937938
@@ -983,12 +984,13 @@ int at_getaddrinfo(const char *nodename, const char *servname,
983984 {
984985 return EAI_FAIL ;
985986 }
986- if (!at_dev_ops )
987+ * res = RT_NULL ;
988+
989+ if (at_dev_ops == RT_NULL )
987990 {
988- LOG_E ("Please register AT device socket options first!" );
989991 return EAI_FAIL ;
990992 }
991- * res = RT_NULL ;
993+
992994 if ((nodename == RT_NULL ) && (servname == RT_NULL ))
993995 {
994996 return EAI_NONAME ;
@@ -1085,10 +1087,10 @@ int at_getaddrinfo(const char *nodename, const char *servname,
10851087 struct sockaddr_in * sa4 = (struct sockaddr_in * ) sa ;
10861088 /* set up sockaddr */
10871089 sa4 -> sin_addr .s_addr = addr .u_addr .ip4 .addr ;
1088- sa4 -> sin_family = AF_AT ;
1090+ sa4 -> sin_family = AF_INET ;
10891091 sa4 -> sin_len = sizeof (struct sockaddr_in );
10901092 sa4 -> sin_port = htons ((u16_t )port_nr );
1091- ai -> ai_family = AF_AT ;
1093+ ai -> ai_family = AF_INET ;
10921094
10931095 /* set up addrinfo */
10941096 if (hints != RT_NULL )
@@ -1114,9 +1116,13 @@ int at_getaddrinfo(const char *nodename, const char *servname,
11141116
11151117void at_freeaddrinfo (struct addrinfo * ai )
11161118{
1117- if (ai != RT_NULL )
1119+ struct addrinfo * next ;
1120+
1121+ while (ai != NULL )
11181122 {
1123+ next = ai -> ai_next ;
11191124 rt_free (ai );
1125+ ai = next ;
11201126 }
11211127}
11221128
0 commit comments