sock_shutdown_bug_tcp.c revision fcdaefeec9091b104adfd3ba967bdebe14c34cdf
1fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly/* 2fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** Copyright 2009 The Android Open Source Project 3fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** 4fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** Licensed under the Apache License, Version 2.0 (the "License"); 5fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** you may not use this file except in compliance with the License. 6fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** You may obtain a copy of the License at 7fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** 8fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** http://www.apache.org/licenses/LICENSE-2.0 9fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** 10fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** Unless required by applicable law or agreed to in writing, software 11fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** distributed under the License is distributed on an "AS IS" BASIS, 12fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** See the License for the specific language governing permissions and 14fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly** limitations under the License. 15fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly*/ 16fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 17fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly#include <stdio.h> 18fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly#include <stdlib.h> 19fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly#include <unistd.h> 20fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly#include <sys/socket.h> 21fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly#include <fcntl.h> 22fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly#include <errno.h> 23fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly#include <netinet/in.h> 24fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 25fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pellyint main(int argc, char **argv) { 26fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly int fd; 27fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly int ret; 28fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly long flags; 29fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly struct sockaddr_in addr; 30fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 31fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly addr.sin_family = AF_INET; 32fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly addr.sin_port = 12348; 33fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 34fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly fd = socket(PF_INET, SOCK_STREAM, 0); 35fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 36fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); 37fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly if (ret < 0) { 38fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly printf("%d errno %d %s\n", __LINE__, errno, strerror(errno)); 39fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly } 40fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 41fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly ret = listen(fd, 1); 42fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly if (ret < 0) { 43fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly printf("%d errno %d %s\n", __LINE__, errno, strerror(errno)); 44fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly } 45fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 46fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly sleep(2); 47fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 48fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly close(fd); 49fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 50fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly sleep(2); 51fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 52fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly fd = socket(PF_INET, SOCK_STREAM, 0); 53fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 54fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); 55fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly if (ret < 0) { 56fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly printf("%d errno %d %s\n", __LINE__, errno, strerror(errno)); 57fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly } 58fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 59fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly sleep(2000000000); 60fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 61fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly return 0; 62fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly} 63fcdaefeec9091b104adfd3ba967bdebe14c34cdfNick Pelly 64