FreeBSD Bugzilla – Attachment 106282 Details for
Bug 146845
[libc] close(2) returns error 54 (connection reset by peer) wrongly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
file.txt
file.txt (text/plain), 4.81 KB, created by
Anton Lavrentiev
on 2010-05-22 23:10:01 UTC
(
hide
)
Description:
file.txt
Filename:
MIME Type:
Creator:
Anton Lavrentiev
Created:
2010-05-22 23:10:01 UTC
Size:
4.81 KB
patch
obsolete
>#include <errno.h> >#include <sys/socket.h> >#include <sys/types.h> >#include <sys/time.h> >#include <netinet/in.h> >#include <stdio.h> >#include <string.h> >#include <stdlib.h> >#include <unistd.h> > >#define BUG > >int main(void) >{ > char buf[40]; > int a, s, len; > struct sockaddr_in sin; > struct linger lg; > pid_t pid; > > if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { > perror("socket"); > return 1; > } > memset(&sin, 0, sizeof(sin)); > sin.sin_len = sizeof(sin); > sin.sin_family = AF_INET; > sin.sin_port = htons(7890); > if (bind(s, (struct sockaddr*) &sin, sizeof(sin)) < 0) { > perror("bind"); > return 1; > } > if (listen(s, 100) < 0) { > perror("listen"); > return 1; > } > if (pid = fork()) { > len = sizeof(sin); > memset(&sin, 0, sizeof(sin)); > if ((a = accept(s, (struct sockaddr*) &sin, &len)) < 0) { > perror("accept"); > return 1; > } > close(s); > s = a; > } else { > close(s); > if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { > perror("socket"); > return 1; > } > if (connect(s, (struct sockaddr*) &sin, sizeof(sin)) < 0) { > perror("connect"); > return 1; > } > } > if (write(s, "Hello\n", 6) < 6) { > perror("write"); > return 1; > } > if ((len = read(s, buf, sizeof(buf))) < 0) { > perror("read"); > return 1; > } > lg.l_linger = 5; > lg.l_onoff = 1; > if (setsockopt(s, SOL_SOCKET, SO_LINGER, &lg, sizeof(lg)) < 0) { > perror("setsockopt"); > return 1; > } > if (pid) { > struct timeval tv = {0, 350000} ; > select(0, 0, 0, 0, &tv); > } >#ifdef BUG > if (shutdown(s, SHUT_WR) < 0) { > perror("shutdown"); > return 1; > } >#endif > errno = 0; > a = close(s); > if (a < 0) > perror("close"); > printf("%.*s %d %d\n", len, buf, a, errno); > return a; >} > >#if 0 > > 68009 a.out CALL socket(PF_INET,SOCK_STREAM,IPPROTO_IP) > 68009 a.out RET socket 3 > 68009 a.out CALL bind(0x3,0xbfbfe9dc,0x10) > 68009 a.out STRU struct sockaddr { AF_INET, 0.0.0.0:7890 } > 68009 a.out RET bind 0 > 68009 a.out CALL listen(0x3,0x64) > 68009 a.out RET listen 0 > 68009 a.out CALL fork > 68009 a.out RET fork 68010/0x109aa > 68010 a.out RET fork 0 > 68009 a.out CALL accept(0x3,0xbfbfe9dc,0xbfbfe9ec) > 68010 a.out CALL close(0x3) > 68010 a.out RET close 0 > 68010 a.out CALL socket(PF_INET,SOCK_STREAM,IPPROTO_IP) > 68010 a.out RET socket 3 > 68010 a.out CALL connect(0x3,0xbfbfe9dc,0x10) > 68010 a.out STRU struct sockaddr { AF_INET, 0.0.0.0:7890 } > 68010 a.out RET connect 0 > 68010 a.out CALL write(0x3,0x8048bc3,0x6) > 68010 a.out GIO fd 3 wrote 6 bytes > "Hello > " > 68009 a.out STRU struct sockaddr { AF_INET, 127.0.0.1:12597 } > 68010 a.out RET write 6 > 68009 a.out RET accept 4 > 68010 a.out CALL read(0x3,0xbfbfe9f0,0x28) > 68009 a.out CALL close(0x3) > 68009 a.out RET close 0 > 68009 a.out CALL write(0x4,0x8048bc3,0x6) > 68009 a.out GIO fd 4 wrote 6 bytes > "Hello > " > 68009 a.out RET write 6 > 68009 a.out CALL read(0x4,0xbfbfe9f0,0x28) > 68010 a.out GIO fd 3 read 6 bytes > "Hello > " > 68010 a.out RET read 6 > 68009 a.out GIO fd 4 read 6 bytes > "Hello > " > 68009 a.out RET read 6 > 68010 a.out CALL setsockopt(0x3,SOL_SOCKET,SO_LINGER,0xbfbfe9d4,0x8) > 68010 a.out RET setsockopt 0 > 68009 a.out CALL setsockopt(0x4,SOL_SOCKET,SO_LINGER,0xbfbfe9d4,0x8) > 68009 a.out RET setsockopt 0 > 68010 a.out CALL shutdown(0x3,<invalid=1>) > 68009 a.out CALL select(0,0,0,0,0xbfbfe9cc) > 68010 a.out RET shutdown 0 > 68010 a.out CALL close(0x3) > 68010 a.out RET close 0 > 68010 a.out CALL write(0x1,0x28201000,0x6) > 68010 a.out GIO fd 1 wrote 6 bytes > "Hello > " > 68010 a.out RET write 6 > 68010 a.out CALL write(0x1,0x28201000,0x5) > 68010 a.out GIO fd 1 wrote 5 bytes > " 0 0 > " > 68010 a.out RET write 5 > 68010 a.out CALL exit(0) > 68009 a.out RET select 0 > 68009 a.out CALL shutdown(0x4,<invalid=1>) > 68009 a.out RET shutdown 0 > 68009 a.out CALL close(0x4) > 68009 a.out RET close -1 errno 54 Connection reset by peer <<<=== BUG!!! > 68009 a.out CALL writev(0x2,0xbfbfe168,0x4) > 68009 a.out GIO fd 2 wrote 32 bytes > "close: Connection reset by peer > " > 68009 a.out RET writev 32/0x20 > 68009 a.out CALL write(0x1,0x28201000,0x6) > 68009 a.out GIO fd 1 wrote 6 bytes > "Hello > " > 68009 a.out RET write 6 > 68009 a.out CALL write(0x1,0x28201000,0x7) > 68009 a.out GIO fd 1 wrote 7 bytes > " -1 54 > " > 68009 a.out RET write 7 > 68009 a.out CALL exit(0xffffffff) > >#endif
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 146845
: 106282 |
106283
|
106284
|
106285
|
252292