FreeBSD Bugzilla – Attachment 213673 Details for
Bug 245817
sendto() can return ENOTCONN on SOCK_STREAM unix socket, which is not documented
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Minimal test program
sendto-enotconn.c (text/plain), 1.05 KB, created by
Erik Inge Bolsø
on 2020-04-22 10:01:25 UTC
(
hide
)
Description:
Minimal test program
Filename:
MIME Type:
Creator:
Erik Inge Bolsø
Created:
2020-04-22 10:01:25 UTC
Size:
1.05 KB
patch
obsolete
>/* Create a socket with nc -U -l /tmp/test.sock */ >/* Stop nc with ^C, should leave a socket file for us */ > >/* compile with cc -o enotconn sendto-enotconn.c */ >/* run as ./enotconn */ > >#include <string.h> >#include <stdio.h> >#include <sys/types.h> >#include <sys/socket.h> >#include <sys/un.h> >#include <netdb.h> >#include <errno.h> >#include <unistd.h> >#include <stdlib.h> /* malloc */ > >int main(int argc, char *argv[]) >{ > int sock; > int ret; > char filename[] = "/tmp/test.sock"; > char buf[] = "Urgle"; > > /* Create a sockaddr_un and socket fd */ > struct sockaddr_un *su = calloc(1, sizeof(struct sockaddr_un)); > > su->sun_family = AF_UNIX; > strncpy(su->sun_path, filename, strlen(filename)); > > int la_sa_len = SUN_LEN(su) + 1; // ref https://redmine.lighttpd.net/issues/2962 > > sock = socket(AF_UNIX, SOCK_STREAM, 0); > if (sock < 0) { > fprintf(stderr, "socket: %s", strerror(errno)); > abort(); > } > > ret = sendto(sock, buf, strlen(buf), 0, (struct sockaddr *)su, la_sa_len); > if (ret < 0) { > if (errno == ENOTCONN) { > fprintf(stderr, "sendto returned ENOTCONN\n"); > } > } >} >
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 245817
: 213673