Index: sys/netgraph/ng_ksocket.c =================================================================== --- sys/netgraph/ng_ksocket.c +++ sys/netgraph/ng_ksocket.c @@ -760,7 +760,7 @@ case NGM_KSOCKET_GETPEERNAME: { int (*func)(struct socket *so, struct sockaddr **nam); - struct sockaddr *sa = NULL; + struct sockaddr_max sam; int len; /* Sanity check */ @@ -774,27 +774,22 @@ if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) ERROUT(ENOTCONN); - func = so->so_proto->pr_peeraddr; + func = so->so_proto->pr_peeraddr_buf; } else - func = so->so_proto->pr_sockaddr; + func = so->so_proto->pr_sockaddr_buf; /* Get local or peer address */ - if ((error = (*func)(so, &sa)) != 0) - goto bail; - len = (sa == NULL) ? 0 : sa->sa_len; + if ((error = (*func)(so, &sam)) != 0) + break; + len = sam.sa_len; /* Send it back in a response */ NG_MKRESPONSE(resp, msg, len, M_NOWAIT); if (resp == NULL) { error = ENOMEM; - goto bail; + break; } bcopy(sa, resp->data, len); - - bail: - /* Cleanup */ - if (sa != NULL) - free(sa, M_SONAME); break; } Index: sys/netinet/in_pcb.c =================================================================== --- sys/netinet/in_pcb.c +++ sys/netinet/in_pcb.c @@ -1978,19 +1978,15 @@ /* * Common routines to return the socket addresses associated with inpcbs. */ -struct sockaddr * -in_sockaddr(in_port_t port, struct in_addr *addr_p) +static void +in_sockaddr(in_port_t port, struct in_addr *addr_p, struct sockaddr *nam) { - struct sockaddr_in *sin; + struct sockaddr_in *sin = (struct sockaddr_sin *)nam; - sin = malloc(sizeof *sin, M_SONAME, - M_WAITOK | M_ZERO); sin->sin_family = AF_INET; sin->sin_len = sizeof(*sin); sin->sin_addr = *addr_p; sin->sin_port = port; - - return (struct sockaddr *)sin; } int @@ -2000,6 +1996,19 @@ struct in_addr addr; in_port_t port; + *nam = malloc(sizeof(struct sockaddr_sin), M_SONAME, + M_WAITOK | M_ZERO); + + return (in_getsockaddr_buf(so, *nam)); +} + +int +in_getsockaddr_buf(struct socket *so, struct sockaddr *nam) +{ + struct inpcb *inp; + struct in_addr addr; + in_port_t port; + inp = sotoinpcb(so); KASSERT(inp != NULL, ("in_getsockaddr: inp == NULL")); Index: sys/sys/protosw.h =================================================================== --- sys/sys/protosw.h +++ sys/sys/protosw.h @@ -91,6 +91,7 @@ typedef int pr_shutdown_t(struct socket *); typedef int pr_flush_t(struct socket *, int); typedef int pr_sockaddr_t(struct socket *, struct sockaddr **); +typedef int pr_sockaddr_buf_t(struct socket *, struct sockaddr *); typedef int pr_sosend_t(struct socket *, struct sockaddr *, struct uio *, struct mbuf *, struct mbuf *, int, struct thread *); typedef int pr_soreceive_t(struct socket *, struct sockaddr **, @@ -143,6 +144,8 @@ pr_sense_t *pr_sense; /* stat(2) */ pr_flush_t *pr_flush; /* XXXGL: merge with pr_shutdown_t! */ pr_sosetlabel_t *pr_sosetlabel; /* MAC, XXXGL: remove */ + + pr_sockaddr_buf_t *pr_sockaddr_buf; }; /*#endif*/