[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MiNT] Problem with bind() socket function



Hello,

I need some help, because this code does not work under
MiNT, but it does under Linux. This is a part of sylpheed,
a mail client using gtk. The bind call in fd_open_unix()
outputs 'bind: invalid argument' under MiNT.

I followed the mintlib bind() call, and it seems that the
error happens in the Fcntl(...,SOCKETCALL), in the socket
device in the kernel. I don't know much about socket
programming, so if anyone has an idea...

--8<--8<--8<--8<-- socket.c bind() test

#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>

int fd_connect_unix(const char *path)
{
	int sock;
	struct sockaddr_un addr;

	sock = socket(PF_UNIX, SOCK_STREAM, 0);
	if (sock < 0) {
		perror("sock_connect_unix(): socket");
		return -1;
	}

	memset(&addr, 0, sizeof(addr));
	addr.sun_family = AF_UNIX;
	strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);

	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
		close(sock);
		return -1;
	}

	return sock;
}

int fd_open_unix(const char *path)
{
	int sock;
	struct sockaddr_un addr;

	sock = socket(PF_UNIX, SOCK_STREAM, 0);

	if (sock < 0) {
		perror("sock_open_unix(): socket");
		return -1;
	}

	memset(&addr, 0, sizeof(addr));
	addr.sun_family = AF_UNIX;
	strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);

	if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
		perror("bind");
		close(sock);
		return -1;
	}

	if (listen(sock, 1) < 0) {
		perror("listen");
		close(sock);
		return -1;		
	}

	return sock;
}

int main(int argc, char **argv)
{
	int uxsock;
	char *path="/tmp/sylpheed-1000";

	uxsock = fd_connect_unix(path);
	if (uxsock < 0) {
		unlink(path);
		return fd_open_unix(path);
	}
}

--8<--8<--8<--8<--
-- 
Patrice Mandin
WWW: http://membres.lycos.fr/pmandin/
Programmeur Linux, Atari
Spécialité: Développement, jeux