qemu_socket.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* headers to use the BSD sockets */
  2. #ifndef QEMU_SOCKET_H
  3. #define QEMU_SOCKET_H
  4. #ifdef _WIN32
  5. #include <windows.h>
  6. #include <winsock2.h>
  7. #include <ws2tcpip.h>
  8. #define socket_error() WSAGetLastError()
  9. int inet_aton(const char *cp, struct in_addr *ia);
  10. #else
  11. #include <sys/types.h>
  12. #include <sys/socket.h>
  13. #include <netinet/in.h>
  14. #include <netinet/tcp.h>
  15. #include <arpa/inet.h>
  16. #include <netdb.h>
  17. #include <sys/un.h>
  18. #define socket_error() errno
  19. #define closesocket(s) close(s)
  20. #endif /* !_WIN32 */
  21. #include "qemu-option.h"
  22. #include "error.h"
  23. #include "qerror.h"
  24. /* misc helpers */
  25. int qemu_socket(int domain, int type, int protocol);
  26. int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
  27. int socket_set_cork(int fd, int v);
  28. void socket_set_block(int fd);
  29. void socket_set_nonblock(int fd);
  30. int send_all(int fd, const void *buf, int len1);
  31. /* callback function for nonblocking connect
  32. * valid fd on success, negative error code on failure
  33. */
  34. typedef void NonBlockingConnectHandler(int fd, void *opaque);
  35. int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp);
  36. int inet_listen(const char *str, char *ostr, int olen,
  37. int socktype, int port_offset, Error **errp);
  38. int inet_connect_opts(QemuOpts *opts, Error **errp,
  39. NonBlockingConnectHandler *callback, void *opaque);
  40. int inet_connect(const char *str, Error **errp);
  41. int inet_nonblocking_connect(const char *str,
  42. NonBlockingConnectHandler *callback,
  43. void *opaque, Error **errp);
  44. int inet_dgram_opts(QemuOpts *opts);
  45. const char *inet_strfamily(int family);
  46. int unix_listen_opts(QemuOpts *opts);
  47. int unix_listen(const char *path, char *ostr, int olen);
  48. int unix_connect_opts(QemuOpts *opts);
  49. int unix_connect(const char *path);
  50. /* Old, ipv4 only bits. Don't use for new code. */
  51. int parse_host_port(struct sockaddr_in *saddr, const char *str);
  52. int socket_init(void);
  53. #endif /* QEMU_SOCKET_H */