FreeBSD Bugzilla – Attachment 217167 Details for
Bug 248614
getpeereid.3 says listen where it means accept.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Client and server that demonstrate the actual behavior of getpeereid
file_248614.txt (text/plain), 2.10 KB, created by
George Nachman
on 2020-08-12 09:06:54 UTC
(
hide
)
Description:
Client and server that demonstrate the actual behavior of getpeereid
Filename:
MIME Type:
Creator:
George Nachman
Created:
2020-08-12 09:06:54 UTC
Size:
2.10 KB
patch
obsolete
>/** BEGIN SERVER **/ >#include <errno.h> >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <sys/socket.h> >#include <sys/un.h> >#include <unistd.h> > >char *socket_path = "./socket"; > >int main(int argc, char *argv[]) { > struct sockaddr_un addr; > char buf[100]; > int fd,cl,rc; > > if (argc > 1) socket_path=argv[1]; > > if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { > perror("socket error"); > exit(-1); > } > > memset(&addr, 0, sizeof(addr)); > addr.sun_family = AF_UNIX; > strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path)-1); > unlink(socket_path); > > if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { > perror("bind error"); > exit(-1); > } > > if (listen(fd, 5) == -1) { > perror("listen error"); > exit(-1); > } > > if ( (cl = accept(fd, NULL, NULL)) == -1) { > perror("accept error"); > exit(-1); > } > uid_t eid=0, egid; > int status = getpeereid(fd, &eid, &egid); > printf("status=%d eid=%d errno=%d\n", status, eid, errno); > status = getpeereid(cl, &eid, &egid); > printf("status=%d eid=%d errno=%d\n", status, eid, errno); > > return 0; >} > >/** BEGIN CLIENT **/ >#include <sys/socket.h> >#include <sys/un.h> >#include <stdio.h> >#include <stdlib.h> >#include <unistd.h> >#include <string.h> > >char *socket_path = "./socket"; > >int main(int argc, char *argv[]) { > struct sockaddr_un addr; > char buf[100]; > int fd,rc; > > if (argc > 1) socket_path=argv[1]; > > if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { > perror("socket error"); > exit(-1); > } > > memset(&addr, 0, sizeof(addr)); > addr.sun_family = AF_UNIX; > if (*socket_path == '\0') { > *addr.sun_path = '\0'; > strncpy(addr.sun_path+1, socket_path+1, sizeof(addr.sun_path)-2); > } else { > strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path)-1); > } > > if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { > perror("connect error"); > exit(-1); > } > > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 248614
: 217167