1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
typedef __SIZE_TYPE__ size_t;
#define NULL ((void *)0)
#define POLLIN 0x001
typedef struct {
unsigned long int __val[(1024 / (8 * sizeof(unsigned long int)))];
} __sigset_t;
typedef unsigned int socklen_t;
struct timespec {
/* [...snip...] */
};
typedef unsigned long int nfds_t;
struct pollfd {
int fd;
short int events;
short int revents;
};
extern int ppoll(struct pollfd *__fds, nfds_t __nfds,
const struct timespec *__timeout, const __sigset_t *__ss);
struct sockaddr_un {
/* [...snip...] */
char sun_path[108];
};
typedef union {
/* [...snip...] */
struct sockaddr_un *__restrict __sockaddr_un__;
/* [...snip...] */
} __SOCKADDR_ARG __attribute__((transparent_union));
extern int accept(int __fd, __SOCKADDR_ARG __addr,
socklen_t *__restrict __addr_len);
extern void *calloc(size_t __nmemb, size_t __size)
__attribute__((__nothrow__, __leaf__))
__attribute__((__malloc__))
__attribute__((__alloc_size__(1, 2)));
extern void *realloc(void *__ptr, size_t __size)
__attribute__((__nothrow__, __leaf__))
__attribute__((__warn_unused_result__))
__attribute__((__alloc_size__(2)));
extern void exit(int __status)
__attribute__((__nothrow__, __leaf__))
__attribute__((__noreturn__));
int main() {
int rc;
int nsockets = 1;
struct pollfd *pollfds, *newpollfds;
struct sockaddr_un remote;
socklen_t len = sizeof(remote);
pollfds = calloc(1, sizeof(struct pollfd));
if (!pollfds) {
exit(1);
}
rc = ppoll(pollfds, nsockets, NULL, NULL);
if (rc < 0) {
exit(2);
}
nsockets++;
newpollfds = realloc(pollfds, nsockets * sizeof(*pollfds));
if (!newpollfds) {
exit(3);
}
pollfds = newpollfds;
pollfds[nsockets - 1].fd = accept(pollfds[0].fd, &remote, &len);
exit(4);
}
|