mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
Use inet_ntop(3) in anet. #apichange
Replace inet_ntoa(3) calls with the more future proof inet_ntop(3) function which is capable of handling additional address families. API Change: anetTcpAccept() & anetPeerToString() additional argument additional argument required to specify the length of the character buffer the IP address is written to in order to comply with inet_ntop(3) function semantics.
This commit is contained in:
parent
e0cb24351c
commit
ef839f9006
12
src/anet.c
12
src/anet.c
@ -431,14 +431,14 @@ static int anetGenericAccept(char *err, int s, struct sockaddr *sa, socklen_t *l
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int anetTcpAccept(char *err, int s, char *ip, int *port) {
|
int anetTcpAccept(char *err, int s, char *ip, size_t ip_len, int *port) {
|
||||||
int fd;
|
int fd;
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
socklen_t salen = sizeof(sa);
|
socklen_t salen = sizeof(sa);
|
||||||
if ((fd = anetGenericAccept(err,s,(struct sockaddr*)&sa,&salen)) == ANET_ERR)
|
if ((fd = anetGenericAccept(err,s,(struct sockaddr*)&sa,&salen)) == ANET_ERR)
|
||||||
return ANET_ERR;
|
return ANET_ERR;
|
||||||
|
|
||||||
if (ip) strcpy(ip,inet_ntoa(sa.sin_addr));
|
if (ip) inet_ntop(sa.sin_family,(void*)&(sa.sin_addr),ip,ip_len);
|
||||||
if (port) *port = ntohs(sa.sin_port);
|
if (port) *port = ntohs(sa.sin_port);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
@ -453,7 +453,7 @@ int anetUnixAccept(char *err, int s) {
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int anetPeerToString(int fd, char *ip, int *port) {
|
int anetPeerToString(int fd, char *ip, size_t ip_len, int *port) {
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
socklen_t salen = sizeof(sa);
|
socklen_t salen = sizeof(sa);
|
||||||
|
|
||||||
@ -463,12 +463,12 @@ int anetPeerToString(int fd, char *ip, int *port) {
|
|||||||
ip[1] = '\0';
|
ip[1] = '\0';
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (ip) strcpy(ip,inet_ntoa(sa.sin_addr));
|
if (ip) inet_ntop(sa.sin_family,(void*)&(sa.sin_addr),ip,ip_len);
|
||||||
if (port) *port = ntohs(sa.sin_port);
|
if (port) *port = ntohs(sa.sin_port);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int anetSockName(int fd, char *ip, int *port) {
|
int anetSockName(int fd, char *ip, size_t ip_len, int *port) {
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
socklen_t salen = sizeof(sa);
|
socklen_t salen = sizeof(sa);
|
||||||
|
|
||||||
@ -478,7 +478,7 @@ int anetSockName(int fd, char *ip, int *port) {
|
|||||||
ip[1] = '\0';
|
ip[1] = '\0';
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (ip) strcpy(ip,inet_ntoa(sa.sin_addr));
|
if (ip) inet_ntop(sa.sin_family,(void*)&(sa.sin_addr),ip,ip_len);
|
||||||
if (port) *port = ntohs(sa.sin_port);
|
if (port) *port = ntohs(sa.sin_port);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -47,14 +47,14 @@ int anetRead(int fd, char *buf, int count);
|
|||||||
int anetResolve(char *err, char *host, char *ipbuf, size_t ipbuf_len);
|
int anetResolve(char *err, char *host, char *ipbuf, size_t ipbuf_len);
|
||||||
int anetTcpServer(char *err, int port, char *bindaddr);
|
int anetTcpServer(char *err, int port, char *bindaddr);
|
||||||
int anetUnixServer(char *err, char *path, mode_t perm);
|
int anetUnixServer(char *err, char *path, mode_t perm);
|
||||||
int anetTcpAccept(char *err, int serversock, char *ip, int *port);
|
int anetTcpAccept(char *err, int serversock, char *ip, size_t ip_len, int *port);
|
||||||
int anetUnixAccept(char *err, int serversock);
|
int anetUnixAccept(char *err, int serversock);
|
||||||
int anetWrite(int fd, char *buf, int count);
|
int anetWrite(int fd, char *buf, int count);
|
||||||
int anetNonBlock(char *err, int fd);
|
int anetNonBlock(char *err, int fd);
|
||||||
int anetEnableTcpNoDelay(char *err, int fd);
|
int anetEnableTcpNoDelay(char *err, int fd);
|
||||||
int anetDisableTcpNoDelay(char *err, int fd);
|
int anetDisableTcpNoDelay(char *err, int fd);
|
||||||
int anetTcpKeepAlive(char *err, int fd);
|
int anetTcpKeepAlive(char *err, int fd);
|
||||||
int anetPeerToString(int fd, char *ip, int *port);
|
int anetPeerToString(int fd, char *ip, size_t ip_len, int *port);
|
||||||
int anetKeepAlive(char *err, int fd, int interval);
|
int anetKeepAlive(char *err, int fd, int interval);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user