netdev->nic = qemu_new_nic(&net_xen_info, &netdev->conf,
"xen", NULL, netdev);
- snprintf(qemu_get_queue(netdev->nic)->info_str,
- sizeof(qemu_get_queue(netdev->nic)->info_str),
- "nic: xenbus vif macaddr=%s", netdev->mac);
+ qemu_get_queue(netdev->nic)->info_str = g_strdup_printf(
+ "nic: xenbus vif macaddr=%s", netdev->mac);
/* fill info */
xenstore_write_be_int(&netdev->xendev, "feature-rx-copy", 1);
NetQueue *incoming_queue;
char *model;
char *name;
- char info_str[256];
+ char *info_str;
NetdevInfo *stored_config;
unsigned receive_disabled : 1;
NetClientDestructor *destructor;
QAPI_CLONE_MEMBERS(NetdevL2TPv3Options,
&nc->stored_config->u.l2tpv3, l2tpv3);
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
- "l2tpv3: connected");
+ s->nc.info_str = g_strdup_printf("l2tpv3: connected");
return 0;
outerr:
qemu_del_net_client(nc);
void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6])
{
- snprintf(nc->info_str, sizeof(nc->info_str),
- "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
- nc->model,
- macaddr[0], macaddr[1], macaddr[2],
- macaddr[3], macaddr[4], macaddr[5]);
+ g_free(nc->info_str);
+ nc->info_str = g_strdup_printf(
+ "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+ nc->model,
+ macaddr[0], macaddr[1], macaddr[2],
+ macaddr[3], macaddr[4], macaddr[5]);
}
static int mac_table[256] = {0};
}
g_free(nc->name);
g_free(nc->model);
+ g_free(nc->info_str);
qapi_free_NetdevInfo(nc->stored_config);
if (nc->destructor) {
nc->destructor(nc);
monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name,
nc->queue_index,
NetClientDriver_str(nc->info->type),
- nc->info_str);
+ nc->info_str ? nc->info_str : "");
if (!QTAILQ_EMPTY(&nc->filters)) {
monitor_printf(mon, "filters:\n");
}
stored->tftp_server_name = g_strdup(tftp_server_name);
}
- snprintf(nc->info_str, sizeof(nc->info_str),
- "net=%s,restrict=%s", inet_ntoa(net),
- restricted ? "on" : "off");
+ nc->info_str = g_strdup_printf("net=%s,restrict=%s", inet_ntoa(net),
+ restricted ? "on" : "off");
s = DO_UPCAST(SlirpState, nc, nc);
s->fd = -1;
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
s->nc.link_down = true;
- memset(s->nc.info_str, 0, sizeof(s->nc.info_str));
+ g_free(s->nc.info_str);
+ s->nc.info_str = g_new0(char, 1);
return;
}
stored->mcast = g_strdup(mcast);
s->dgram_dst = saddr;
- snprintf(nc->info_str, sizeof(nc->info_str),
- "socket: fd=%d (cloned mcast=%s:%d)",
- fd, inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+ nc->info_str = g_strdup_printf("socket: fd=%d (cloned mcast=%s:%d)",
+ fd, inet_ntoa(saddr.sin_addr),
+ ntohs(saddr.sin_port));
} else {
if (sa_type == SOCKET_ADDRESS_TYPE_UNIX) {
s->dgram_dst.sin_family = AF_UNIX;
}
- snprintf(nc->info_str, sizeof(nc->info_str),
- "socket: fd=%d %s", fd, SocketAddressType_str(sa_type));
+ nc->info_str = g_strdup_printf("socket: fd=%d %s",
+ fd, SocketAddressType_str(sa_type));
}
return s;
nc = qemu_new_net_client(&net_socket_info, peer, model, name);
- snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd);
+ nc->info_str = g_strdup_printf("socket: fd=%d", fd);
s = DO_UPCAST(NetSocketState, nc, nc);
stored->has_fd = true;
stored->fd = g_strdup_printf("%d", fd);
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
- "socket: connection from %s:%d",
- inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+ g_free(s->nc.info_str);
+ s->nc.info_str = g_strdup_printf("socket: connection from %s:%d",
+ inet_ntoa(saddr.sin_addr),
+ ntohs(saddr.sin_port));
}
static int net_socket_listen_init(NetClientState *peer,
stored->has_connect = true;
stored->connect = g_strdup(host_str);
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
- "socket: connect to %s:%d",
- inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+ g_free(s->nc.info_str);
+ s->nc.info_str = g_strdup_printf("socket: connect to %s:%d",
+ inet_ntoa(saddr.sin_addr),
+ ntohs(saddr.sin_port));
return 0;
}
stored->localaddr = g_strdup(localaddr_str);
}
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
- "socket: mcast=%s:%d",
- inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+ g_free(s->nc.info_str);
+ s->nc.info_str = g_strdup_printf("socket: mcast=%s:%d",
+ inet_ntoa(saddr.sin_addr),
+ ntohs(saddr.sin_port));
return 0;
}
stored->has_udp = true;
stored->udp = g_strdup(rhost);
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
- "socket: udp=%s:%d",
- inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port));
+ g_free(s->nc.info_str);
+ s->nc.info_str = g_strdup_printf("socket: udp=%s:%d",
+ inet_ntoa(raddr.sin_addr),
+ ntohs(raddr.sin_port));
return 0;
}
stored->has_ifname = true;
stored->ifname = g_strdup(ifname);
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
- "tap: ifname=%s", ifname);
+ s->nc.info_str = g_strdup_printf("tap: ifname=%s", ifname);
s->handle = handle;
stored->helper = g_strdup(helper);
}
- snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper,
- br);
+ s->nc.info_str = g_strdup_printf("helper=%s,br=%s", helper, br);
return 0;
}
g_free(tmp_s);
}
- snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);
+ s->nc.info_str = g_strdup_printf("fd=%d", fd);
} else if (tap->has_helper) {
if (!stored->has_helper) {
stored->has_helper = true;
g_strdup(DEFAULT_BRIDGE_INTERFACE);
}
- snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s",
- tap->helper);
+ s->nc.info_str = g_strdup_printf("helper=%s", tap->helper);
} else {
if (ifname && !stored->has_ifname) {
stored->has_ifname = true;
stored->downscript = g_strdup(downscript);
}
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
- "ifname=%s,script=%s,downscript=%s", ifname, script,
- downscript);
+ s->nc.info_str = g_strdup_printf("ifname=%s,script=%s,downscript=%s",
+ ifname, script, downscript);
if (strcmp(downscript, "no") != 0) {
snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
nc = qemu_new_net_client(&net_vde_info, peer, model, name);
- snprintf(nc->info_str, sizeof(nc->info_str), "sock=%s,fd=%d",
- sock, vde_datafd(vde));
+ nc->info_str = g_strdup_printf("sock=%s,fd=%d", sock, vde_datafd(vde));
s = DO_UPCAST(VDEState, nc, nc);
user = g_new0(struct VhostUserState, 1);
for (i = 0; i < queues; i++) {
nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name);
- snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s",
- i, chr->label);
+ nc->info_str = g_strdup_printf("vhost-user%d to %s", i, chr->label);
nc->queue_index = i;
if (!nc0) {
nc0 = nc;
stored->has_queues = true;
stored->queues = 1; /* TODO: change when support multiqueue */
- snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA);
+ nc->info_str = g_strdup_printf(TYPE_VHOST_VDPA);
nc->queue_index = 0;
s = DO_UPCAST(VhostVDPAState, nc, nc);
vdpa_device_fd = qemu_open_old(vhostdev, O_RDWR);