Changeset 378:41e3c2a3721c in freeDiameter for freeDiameter/cnxctx.c
- Timestamp:
- Jul 5, 2010, 4:21:22 PM (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/cnxctx.c
r258 r378 37 37 #include "cnxctx.h" 38 38 39 #include <net/if.h> 40 #include <ifaddrs.h> /* for getifaddrs */ 41 39 42 /* The maximum size of Diameter message we accept to receive (<= 2^24) to avoid too big mallocs in case of trashed headers */ 40 43 #ifndef DIAMETER_MSG_SIZE_MAX 41 44 #define DIAMETER_MSG_SIZE_MAX 65535 /* in bytes */ 42 45 #endif /* DIAMETER_MSG_SIZE_MAX */ 46 43 47 44 48 /* Connections contexts (cnxctx) in freeDiameter are wrappers around the sockets and TLS operations . … … 74 78 */ 75 79 76 77 80 /*******************************************/ 78 81 /* Creation of a connection object */ … … 468 471 469 472 /* Get the list of endpoints (IP addresses) of the local and remote peers on this connection */ 470 int fd_cnx_getendpoints(struct cnxctx * conn, struct fd_list * local, struct fd_list * remote) 471 { 472 TRACE_ENTRY("%p %p %p", conn, local, remote); 473 CHECK_PARAMS(conn); 474 475 if (local) { 476 /* Retrieve the local endpoint(s) of the connection */ 477 switch (conn->cc_proto) { 478 case IPPROTO_TCP: { 479 sSS ss; 480 socklen_t sl; 481 CHECK_FCT(fd_tcp_get_local_ep(conn->cc_socket, &ss, &sl)); 482 CHECK_FCT(fd_ep_add_merge( local, (sSA *)&ss, sl, EP_FL_LL | EP_FL_PRIMARY)); 483 } 484 break; 485 486 #ifndef DISABLE_SCTP 487 case IPPROTO_SCTP: { 488 CHECK_FCT(fd_sctp_get_local_ep(conn->cc_socket, local)); 489 } 490 break; 491 #endif /* DISABLE_SCTP */ 492 493 default: 494 CHECK_PARAMS(0); 495 } 496 } 497 498 if (remote) { 499 /* Check we have a full connection object, not a listening socket (with no remote) */ 500 CHECK_PARAMS( conn->cc_incoming ); 501 502 /* Retrieve the peer endpoint(s) of the connection */ 503 switch (conn->cc_proto) { 504 case IPPROTO_TCP: { 505 sSS ss; 506 socklen_t sl; 507 CHECK_FCT(fd_tcp_get_remote_ep(conn->cc_socket, &ss, &sl)); 508 CHECK_FCT(fd_ep_add_merge( remote, (sSA *)&ss, sl, EP_FL_LL | EP_FL_PRIMARY )); 509 } 510 break; 511 512 #ifndef DISABLE_SCTP 513 case IPPROTO_SCTP: { 514 CHECK_FCT(fd_sctp_get_remote_ep(conn->cc_socket, remote)); 515 } 516 break; 517 #endif /* DISABLE_SCTP */ 518 519 default: 520 CHECK_PARAMS(0); 521 } 473 int fd_cnx_getremoteeps(struct cnxctx * conn, struct fd_list * eps) 474 { 475 TRACE_ENTRY("%p %p %p", conn, eps); 476 CHECK_PARAMS(conn && eps); 477 478 /* Check we have a full connection object, not a listening socket (with no remote) */ 479 CHECK_PARAMS( conn->cc_incoming ); 480 481 /* Retrieve the peer endpoint(s) of the connection */ 482 switch (conn->cc_proto) { 483 case IPPROTO_TCP: { 484 sSS ss; 485 socklen_t sl; 486 CHECK_FCT(fd_tcp_get_remote_ep(conn->cc_socket, &ss, &sl)); 487 CHECK_FCT(fd_ep_add_merge( eps, (sSA *)&ss, sl, EP_FL_LL | EP_FL_PRIMARY )); 488 } 489 break; 490 491 #ifndef DISABLE_SCTP 492 case IPPROTO_SCTP: { 493 CHECK_FCT(fd_sctp_get_remote_ep(conn->cc_socket, eps)); 494 } 495 break; 496 #endif /* DISABLE_SCTP */ 497 498 default: 499 CHECK_PARAMS(0); 522 500 } 523 501 524 502 return 0; 525 503 } 526 527 504 528 505 /* Get a string describing the remote peer address (ip address or fqdn) */ … … 531 508 CHECK_PARAMS_DO( conn, return "" ); 532 509 return conn->cc_remid; 510 } 511 512 /* Retrieve a list of all IP addresses of the local system from the kernel, using */ 513 int fd_cnx_get_local_eps(struct fd_list * list) 514 { 515 struct ifaddrs *iflist, *cur; 516 CHECK_SYS(getifaddrs(&iflist)); 517 518 for (cur = iflist; cur != NULL; cur = cur->ifa_next) { 519 if (cur->ifa_flags & IFF_LOOPBACK) 520 continue; 521 522 if (fd_g_config->cnf_flags.no_ip4 && (cur->ifa_addr->sa_family == AF_INET)) 523 continue; 524 525 if (fd_g_config->cnf_flags.no_ip6 && (cur->ifa_addr->sa_family == AF_INET6)) 526 continue; 527 528 CHECK_FCT(fd_ep_add_merge( list, cur->ifa_addr, sSAlen(cur->ifa_addr), EP_FL_LL )); 529 } 530 531 freeifaddrs(iflist); 532 533 return 0; 533 534 } 534 535
Note: See TracChangeset
for help on using the changeset viewer.