Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: 'sockaddr_in' was not declared in this scope #83

Closed
Rhialto opened this issue Oct 8, 2015 · 5 comments
Closed

error: 'sockaddr_in' was not declared in this scope #83

Rhialto opened this issue Oct 8, 2015 · 5 comments

Comments

@Rhialto
Copy link

Rhialto commented Oct 8, 2015

I'm packaging fs-uae-2.7.2dev for in pkgsrc-wip (now available via http://pkgsrc.org/wip/ ). Compiling on NetBSD I ran into the following:

--- src/support/socket.o ---
depbase=`echo src/support/socket.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`; c++ -DHA
VE_CONFIG_H -I.   -DUAE -DFSUAE -I./flac/include  -I./gen -I./src -I./src/jit -I
./src/include  -I./src/od-fs -I./src/od-fs/include -I./src/od-win32  -I./src/od-
win32/caps -I./libfsemu/include   -I./manymouse   -I./src/slirp/include -I./libu
dis86/include   -I./prowizard/include -I./softfloat -I./libmpeg2/include -I/usr/
pkg/include -I/usr/X11R7/include -I/usr/include -I/usr/X11R7/include/libdrm -I/u
sr/pkg/include/SDL2 -I/usr/X11R7/include/freetype2 -I/usr/X11R7/include/freetype
2 -I/usr/X11R7/include  -D_REENTRANT -I/usr/X11R7/include  -pthread -I/usr/pkg/i
nclude/glib/glib-2.0 -I/usr/pkg/lib/glib-2.0/include -I/usr/pkg/include  -DLUA_U
SE_POSIX  -I/usr/pkg/include  -D_REENTRANT -I/usr/X11R7/include  -I/usr/pkg/include/libpng16   -D_REENTRANT -D_THREAD_SAFE -I/usr/pkg/include/SDL2 -I/usr/X11R7/include    -fno-strict-overflow  -Wmissing-declarations -Waddress -fvisibility=hidden   -O2 -I/usr/pkg/include -I/usr/X11R7/include -I/usr/include -I/usr/X11R7/include/libdrm -I/usr/pkg/include/SDL2 -I/usr/X11R7/include/freetype2 -MT src/support/socket.o -MD -MP -MF $depbase.Tpo -c -o src/support/socket.o src/support/socket.cpp && mv -f $depbase.Tpo $depbase.Po
--- src/support/socket.o ---
src/support/socket.cpp: In function 'uae_socket uae_socket_accept(uae_socket)':
src/support/socket.cpp:167:28: error: 'sockaddr_in' was not declared in this scope
src/support/socket.cpp:169:51: error: 'socketaddr' was not declared in this scope
*** [src/support/socket.o] Error code 1

make: stopped in /pkg_comp/obj/pkgsrc/wip/fs-uae-dev/default/fs-uae-2.7.2dev
1 error

Looking into this, I found that the only use of sockaddr_in is in this fragment:

uae_socket uae_socket_accept(uae_socket s)
{
        socklen_t sa_len = sizeof(SOCKADDR_INET);
        char socketaddr[sizeof(SOCKADDR_INET)];
        uae_socket result = accept(s, (struct sockaddr*) socketaddr, &sa_len);
        return result;
}

sa_len should be the value from struct addrinfo.ai_addrlen.
if you're not interested in the value, like here, just use a dummy size. My manual doesn't say what happens if the value is too small, so using a size at least big enough for IPv6 addresses is probably wise.

I stubbed in 64 and with that there were no more build complaints.

@rofl0r
Copy link

rofl0r commented Oct 9, 2015

the right fix is probably to just #include <netinet/in.h>

@Rhialto
Copy link
Author

Rhialto commented Oct 9, 2015

That would work too, for IPv4 connections, but not for IPv6 (unless the implementation happens to have lots of spare room in sockaddr_in).

@rofl0r
Copy link

rofl0r commented Oct 9, 2015

usually one uses sockaddr_storage, to fit in both sockaddr_in and sockaddr_in6.

@FrodeSolheim
Copy link
Owner

@rofl0r using sockaddr_storage was a good tip.
@Rhialto can you check if the following patch is sufficient for NetBSD? a9cb4a2 (looks like sys/socket.h should define sockaddr_storage http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/socket.h.html)

@Rhialto
Copy link
Author

Rhialto commented Oct 12, 2015

Yes, that looks sufficient. (given my build environment I just tested it by replacing the socket.c file in the ...dev release). sys/socket.h does indeed define struct sockaddr_storage. (well unless one starts using those things like POSIX_SOURCE etc but that is usually a bad idea anyway)

@Rhialto Rhialto closed this as completed Oct 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants