re-indented
FossilOrigin-Name: 0c65f09d66682d7f92fb37c44d9c7a406ffd59e16623dfee579392a5bc4c25aa
This commit is contained in:
parent
130df27488
commit
eb90a1bcad
@ -35,10 +35,10 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
#ifdef AF_LINK
|
#ifdef AF_LINK
|
||||||
# include <net/if_dl.h>
|
#include <net/if_dl.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef AF_PACKET
|
#ifdef AF_PACKET
|
||||||
# include <netpacket/packet.h>
|
#include <netpacket/packet.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
@ -49,62 +49,64 @@
|
|||||||
* @param s Destination buffer
|
* @param s Destination buffer
|
||||||
* @param maxlen Size of destination buffer
|
* @param maxlen Size of destination buffer
|
||||||
* @param addport If true then the port number wil be added to the output
|
* @param addport If true then the port number wil be added to the output
|
||||||
|
*
|
||||||
* Works only for sockaddrs of type AF_INET, AF_INET6, AF_PACKET, AF_LINK.
|
* Works only for sockaddrs of type AF_INET, AF_INET6, AF_PACKET, AF_LINK.
|
||||||
*/
|
*/
|
||||||
char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen,int addport)
|
char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen, int addport)
|
||||||
{
|
{
|
||||||
char d[maxlen];
|
char d[maxlen];
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
|
|
||||||
switch(sa->sa_family) {
|
switch (sa->sa_family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
inet_ntop(AF_INET, &(((struct sockaddr_in *)sa)->sin_addr), d, maxlen);
|
inet_ntop(AF_INET, &(((struct sockaddr_in *) sa)->sin_addr), d,
|
||||||
if (addport){
|
maxlen);
|
||||||
port = ((struct sockaddr_in *)sa)->sin_port;
|
if (addport) {
|
||||||
sprintf(s,"%s:%i",d,ntohs(port));
|
port = ((struct sockaddr_in *) sa)->sin_port;
|
||||||
}
|
sprintf(s, "%s:%i", d, ntohs(port));
|
||||||
else
|
} else
|
||||||
sprintf(s,"%s",d);
|
sprintf(s, "%s", d);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)sa)->sin6_addr), d, maxlen);
|
inet_ntop(AF_INET6, &(((struct sockaddr_in6 *) sa)->sin6_addr), d,
|
||||||
if (addport){
|
maxlen);
|
||||||
port = ((struct sockaddr_in6 *)sa)->sin6_port;
|
if (addport) {
|
||||||
sprintf(s,"[%s]:%i",d,ntohs(port));
|
port = ((struct sockaddr_in6 *) sa)->sin6_port;
|
||||||
}
|
sprintf(s, "[%s]:%i", d, ntohs(port));
|
||||||
else
|
} else
|
||||||
sprintf(s,"%s",d);
|
sprintf(s, "%s", d);
|
||||||
break;
|
break;
|
||||||
#ifdef AF_LINK
|
#ifdef AF_LINK
|
||||||
case AF_LINK:
|
case AF_LINK:
|
||||||
{
|
{
|
||||||
struct sockaddr_dl *sl=(struct sockaddr_dl*)sa;
|
struct sockaddr_dl *sl = (struct sockaddr_dl *) sa;
|
||||||
sock_hwaddrtostr(((uint8_t*)sl->sdl_data)+sl->sdl_nlen,sl->sdl_alen,s,":");
|
sock_hwaddrtostr(((uint8_t *) sl->sdl_data) + sl->sdl_nlen,
|
||||||
|
sl->sdl_alen, s, ":");
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#endif /* AF_LINLK */
|
#endif /* AF_LINLK */
|
||||||
|
|
||||||
#ifdef AF_PACKET
|
#ifdef AF_PACKET
|
||||||
case AF_PACKET:
|
case AF_PACKET:
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *sp=s;
|
char *sp = s;
|
||||||
struct sockaddr_ll *sl=(struct sockaddr_ll*)sa;
|
struct sockaddr_ll *sl = (struct sockaddr_ll *) sa;
|
||||||
for (i=0; i<sl->sll_halen-1; i++){
|
for (i = 0; i < sl->sll_halen - 1; i++) {
|
||||||
sprintf(sp,"%02X:",sl->sll_addr[i]);
|
sprintf(sp, "%02X:", sl->sll_addr[i]);
|
||||||
sp+=3;
|
sp += 3;
|
||||||
}
|
|
||||||
sprintf(sp,"%02X",sl->sll_addr[i]);
|
|
||||||
}
|
}
|
||||||
|
sprintf(sp, "%02X", sl->sll_addr[i]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* AF_PACKET */
|
#endif /* AF_PACKET */
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
strncpy(s, "Unknown AF", maxlen);
|
strncpy(s, "Unknown AF", maxlen);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -114,4 +116,3 @@ char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen,int addpo
|
|||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user