Is this error expected?

const std = @import("std");
const net = std.net;
const posix = std.posix;
const mem = std.mem;

pub fn main() !void {
    var addr = try net.Address.parseIp("127.0.0.1", 33333);
    const socket_fd = try posix.socket(addr.any.family, posix.SOCK.STREAM, posix.IPPROTO.TCP);

    const socket_len: posix.socklen_t = addr.getOsSockLen();

    try posix.setsockopt(
        socket_fd,
        posix.SOL.SOCKET,
        posix.SO.REUSEADDR,
        &mem.toBytes(@as(c_int, 1)),
    );

    try posix.bind(socket_fd, &addr.any, &socket_len);
    try posix.listen(socket_fd, 10);
    try posix.accept(socket_fd, &addr.any, &socket_len, 0);
}

I got the following error:

main.zig:106:42: error: expected type u32 , found pointer 
  try posix.bind(socket_fd, &addr.any, &socket_len);

main.zig:106:42: note: address-of operator always returns a pointer
referenced by:
  callMain: /home/caporegime/Softwares/bin/zig-linux-x86_64-0.13.0/11b/std/start.zig:524:32 
  callMainWithArgs: /home/caporegime/Softwares/bin/zig-linux-x86_64-0.13.0/11b/std/start.zig:482:12   remaining reference traces hidden; use '-freference-trace' to see all reference traces
  remaining reference traces hidden; use '-freference-trace' to see all reference traces

I found it weird that I can’t pass the non-null type to the nullable-argument of the same type.

System info:

OS: Debian 12
Zig version: 0.13.0

It’s expecting a pointer and you’re passing a value.

try

posix.accept(socket_fd, &addr.any, &socket_len, 0);
                                   ^

Yeah, my bad I pasted the wrong version code. I will update it shortly.

When I did change it to &socket_len it emitted the error:

expected type u32 found pointer

My bad, I posted the wrong version of the code and error message (over undo).

Tks for your time.

bind takes a value u32, accept takes a pointer to u32.

Tks so much for your patience.

I just getting started with zig!

somehow I missed that subttle difference in the function signature :slight_smile: